var mpb ={
	create: function(pId, file){
        var htm;
        htm = '<audio src="https://st.92kk.com/mac.mp3" id="audio"></audio><div class="player-progress-bg" id="p-pb" onclick="click_progress()"><div class="player-progress" id="p-pg"></div><span class="player-bar" id="p-bar"></span></div><div class="player-more"><div class="player-btn"><a href="javascript:previouSong();" class="player-up"></a><a href="javascript:player_play()"class="player-play "id="p-play"></a><a href="javascript:nextSong();" class="player-down"></a><div class="control"><div class="volume"><div href="javascript:void(0);" onclick="muted(\'firefox\',this);" class="control mute icon" id="m-play"></div><div class="slider nen"><div class="volume_n"></div></div></div></div><div class="other"><span class="palyer-tips" id="p-tips">等待连接</span><span class="palyer-name" id="p-name"></span><span id="p-time1">00:00</span>&nbsp;/&nbsp;<span id="p-time2">00:00</span></div></div></div>'
    	document.getElementById(pId).innerHTML = htm;
	}
};

mpb.create("pFlash");
var ps=1;

function nextSong(){
        var nums=$('.play-itemx').length;
		 if(ps==nums){
			 var xid=1;
		 }else{
			 var xid=ps+1;
		 }
         playss(xid);
}
	
function previouSong(){
         var nums=$('.play-itemx').length;
		 if(ps==1){
			 var sid=nums;
		 }else{
			 var sid=ps-1;
		 }
         playss(sid);
}
	

function playss(n){
	$('#players').show();
	$("#pause_"+ps).hide();
	$("#listss_"+ps).show();
	$("#pause_"+n).show();
	$("#listss_"+n).hide();
	ps=n;
	did=$('#listss_'+ps).attr('data_did');
    if(did == undefined) {
        playss(1);
    }else{ 
        setTimeout(plays,1000);
    }
    if(isMac){
    		audio.play();
    		$('#p-play').removeClass('player-pause');
    		clearInterval(player);
    		$('#p-tips').html('暂停中...');
    }
}

function plays(){
       did=$('#listss_'+ps).attr('data_did');
       var name=$('#listss_'+ps).attr('data_name');
	   var url=$('#listss_'+ps).attr('data_url');
	   var urlb=strencode(url);
       var vodurl = 'https://st.92kk.com/'+urlb;
       var vodurl2 = 'https://st.92kk.com/'+urlb;
        $('audio').attr('src',vodurl);
        $('#p-name').html(name);
    	player_play();
    	var vid = document.getElementById("audio");
    	vid.onerror = function() {
    	    $('audio').attr('src',vodurl2);
    	    $('#p-tips').html('连接中...');
    	    player_play();
    	    var vid = document.getElementById("audio");
        	vid.onerror = function() {
        	    $('audio').attr('src',vodurl);
        	    $('#p-tips').html('连接中...');
        	    player_play();
            	var vid = document.getElementById("audio");
            	vid.onerror = function() {
            	    $('#p-tips').html('播放失败...');
            	    audio.pause();
            	    layer.confirm('播放失败进入下一首...', {
                      btn: ['好的'] 
                    }, function(){
                       nextSong();
                    });
            	};
        	};
    	};
}

var audio = document.getElementById("audio");    
audio.addEventListener("ended", function(){
  nextSong();
});

var isMac = /macintosh|mac os safari/i.test(navigator.userAgent);
var Lath = document.getElementById("audio").volume = 1;
$(".volume_n").css("width", Lath * 100);
$('.nen').click(function (e) {
    var volWidth = $('.nen').width();
    var lata = (e.offsetX - ($(this).width() - volWidth) / 2) / volWidth;
    document.getElementById("audio").volume = lata;
    $(".volume_n").css("width", lata * 100);
});

function muted(){
	if(audio.muted){
		audio.muted = false;
		$('#m-play').removeClass('enable');
	}else{
		audio.muted = true; 
		$('#m-play').addClass('enable');
	}
}

function player_play(sign){
	if(sign==1){
		audio.play();
		$('#p-play').addClass('player-pause');
		player = setInterval("player_progress()","20");
		$('#p-tips').html('正在播放:');return;
	}
	if(audio.paused){
		audio.play();
		$('#p-play').addClass('player-pause');
		player = setInterval("player_progress()","20");
		$('#p-tips').html('正在播放:');
	}else{
		audio.pause();
		$('#p-play').removeClass('player-pause');
		clearInterval(player);
		$('#p-tips').html('暂停中...');
	}
}

function player_progress(){
	var nowtime = audio.currentTime;
	var alltime = audio.duration;
	$('#p-time1').html(timetostr(audio.currentTime));
	$('#p-time2').html(timetostr(audio.duration));
	var play_jd = nowtime/alltime*100+'%';
	$('#p-pg').css('width', play_jd);
	$('#p-bar').css('left', play_jd);
}

function timetostr(second){
	return [ parseInt(second / 60), parseInt(second % 60)].join(":").replace(/\b(\d)\b/g, "0$1");
}

function click_progress(){
	var l = $('#p-pb').offset().left;
	var w = parseInt($('#p-pb').width());
	var e = event || window.event;
    var p = e.pageX;
    var pro = (p-l)/w;
    audio.currentTime = audio.duration*pro;
}

function strencode(string) {
	string = Base64.decode(string);
	eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('0 1="2";0 3=1.5;0 4="";',6,6,'var|idc|1121|len|code|length'.split('|'),0,{}))
	for (i = 0; i < string.length; i++) {
		k = i % len;
		code += String.fromCharCode(string.charCodeAt(i) ^ idc.charCodeAt(k));
	}
	return Base64.decode(code);
}